package thread;

/**
 * @author SWJ
 * @create 2021-06-22 16:31
 * 创建多线程编程方式1
 */
public class Thread1 {
    public static void main(String[] args) {
        MyThread t = new MyThread();
        /**对应的就是线程的新建状态*/
        MyThread t2 = new MyThread();
        MyThread t3 = new MyThread("t3线程");
//        t.run();
//        t2.run();
//        t3.run();
        t.start();
        t2.start();
        t3.start();
        /**"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\lib\idea_rt.jar=54610:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;D:\软件\idea\out\production\ModuleOop2" thread.Thread1
         1=Thread-1
         1=Thread-0
         2=Thread-1
         2=Thread-0
         3=Thread-0
         4=Thread-0
         3=Thread-1
         5=Thread-0
         4=Thread-1
         5=Thread-1
         6=Thread-1
         7=Thread-1
         8=Thread-1
         9=Thread-1
         10=Thread-1
         6=Thread-0
         7=Thread-0
         8=Thread-0
         9=Thread-0
         10=Thread-0
         Process finished with exit code 0
         多线程抢占
         */
    }
}

//1自定义多线程类

/**
 * 方式一时通过extends Thead
 */
class MyThread extends Thread {
    public MyThread() {
        super();
        //子类调用父类构造方法
    }

    /**创建子类的构造方法*/
    public MyThread(String name) {
        super(name);
    }

    /**
     * 增加重写的功能，写自己的业务
     */
    @Override
    public void run() {
//        super.run();

        /**调用父类run方法
         * 需求：循环输出10次当前正在执行线程的名称
         * */

        for (int i = 1; i <= 10; i++) {
            System.out.println(i + "=" + getName());
            //返回该线程名称
        }

    }
}

